package com;

import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import com.fz.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2018-01-16.
 */
public class Demo {
    @Test
    public void abc() throws IOException {
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-conf.xml"));
        SqlSession session = sf.openSession();
        //Connection conn = session.getConnection(); //使用jdbc自己处理
        StudentMapper sdao = session.getMapper(StudentMapper.class);
        List<Map<String,Object>> v = sdao.query();
        for(Map<String,Object> m : v){
            for(String k : m.keySet()){
                System.out.println(m.get(k));
            }
            System.out.println("-----------------------------");
        }

        BookMapper bdao = session.getMapper(BookMapper.class);
        List<Book> bks = bdao.query();
        for(Book b : bks){
            System.out.println(b);
        }
    }
}
